package com.shiro.service;

import com.shiro.entity.Permissions;
import com.shiro.entity.Role;
import com.shiro.entity.User;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@Service
public class LoginServiceImpl implements LoginService {

    @Override
    public User getUserByName(String getMapByName) {
        return getMapByName(getMapByName);
    }

    /**
     * 模拟数据库查询
     *
     * @param userName 用户名
     * @return User
     */
    private User getMapByName(String userName) {
        Permissions permissions1 = new Permissions("1", "query");
        Permissions permissions2 = new Permissions("2", "add");
        Set<Permissions> permissionsSet = new HashSet<>();
        permissionsSet.add(permissions1);
        permissionsSet.add(permissions2);
        Role role = new Role("1", "admin", permissionsSet);
        Set<Role> roleSet = new HashSet<>();
        roleSet.add(role);
        User user = new User("1", "wsl", "123456", roleSet);
        Map<String, User> map = new HashMap<>();
        map.put(user.getUserName(), user);
        
        Set<Permissions> permissionsSet1 = new HashSet<>();
        permissionsSet1.add(permissions1);
        Role role1 = new Role("2", "user", permissionsSet1);
        Set<Role> roleSet1 = new HashSet<>();
        roleSet1.add(role1);
        User user1 = new User("2", "zhangsan", "123456", roleSet1);
        map.put(user1.getUserName(), user1);
        return map.get(userName);

       /* Permissions permissions1 = new Permissions("1", "query");
        Permissions permissions2 = new Permissions("2", "add");
        Permissions permissions3 = new Permissions("3", "del");
        Permissions permissions4 = new Permissions("4", "edit");

        HashSet<Permissions> permissions = new HashSet<>();
        permissions.add(permissions1);
        permissions.add(permissions2);
        permissions.add(permissions3);
        permissions.add(permissions4);

        Role role = new Role("1", "admin", permissions);
        HashSet<Role> roleHashSet = new HashSet<>();
        roleHashSet.add(role);

        User user = new User("1", "fjw", "123456", roleHashSet);
        HashMap<String, User> map = new HashMap<>();
        map.put(user.getUserName(),user);

        HashSet<Permissions> userPermissions = new HashSet<>();
        userPermissions.add(permissions1);
        userPermissions.add(permissions2);

        HashSet<Role> roles = new HashSet<>();
        Role guestRole = new Role("2", "guest", userPermissions);
        roles.add(guestRole);

        User zhangsan = new User("2", "zhangsan", "123456", roles);

        map.put(zhangsan.getUserName(),zhangsan);
        return map.get(userName);*/

    }
}